//
//  ByCellUserMessageNotify.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/7.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByCellUserMessageNotify.h"

@implementation ByCellUserMessageNotify
{
    UILabel *_titleLabel;
    UILabel *_contentLabel;
    UILabel *_timeLabel;
}
+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellUserMessageNotify";
    ByCellUserMessageNotify *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _timeLabel = [[UILabel alloc] init];
    [self addSubview:_timeLabel];
    _timeLabel.font = FONT(12);
    _timeLabel.textColor = [UIColor lightGrayColor];
    _timeLabel.textAlignment = NSTextAlignmentRight;
    
    _titleLabel = [[UILabel alloc] init];
    [self addSubview:_titleLabel];
    _titleLabel.font = FONT(14);
    
    _contentLabel = [[UILabel alloc] init];
    [self addSubview:_contentLabel];
    _contentLabel.font = FONT(12);
}

- (void)setModel:(ByModelUserMessageNotify *)model{
    _model = model;
    
    // 时间
    CGFloat width = [_model.create_time getSizeOfString:12].width + 10;
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(width, 15));
    }];
    
     // 标题
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(10));
        make.right.equalTo(_timeLabel.mas_left);
        make.height.equalTo(@(15));
    }];
    
    //  内容
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.left.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 15));
    }];
    
    //  测试数据
    _titleLabel.text = _model.title;
    _timeLabel.text = _model.create_time;
    _contentLabel.text = _model.content;
}

@end
